<template>
	<view class="page">
		<!-- #ifndef MP-WEIXIN-->
		<my-navbar leftText="更改密码" @leftClick="back"></my-navbar>
		<!-- #endif -->
		<view class="edit">
			<view class="row">
				<view class="prop">旧密码</view>
				<input type="password" :value="old" @input="inputAction($event,'old')" placeholder="请输入旧密码" />
			</view>
			<view class="row">
				<view class="prop">新密码</view>
				<input type="password" :value="isnew" @input="inputAction($event,'isnew')" placeholder="请输入六位及以上的密码" />
			</view>
			<view class="row">
				<view class="prop">确认新密码</view>
				<input type="password" :value="renew" @keyup="renew=renew.replace(/\s+/g,'')"  @input="inputAction($event,'renew')" placeholder="请重复密码" />
			</view>
			<view class="tips" v-if="showTips">两次密码不一致</view>
		</view>
		<view class="submit flex-center fonts_26" @click="submit">保存</view>
	</view>
</template>

<script>
	import {$https} from '@/static/js/request.js';
	export default {
		data() {
			return {
				old:'',
				isnew:'',
				renew:'',
				showTips:false,
			};
		},
		onReady(){
			getApp().setTitle()
		},
		onLoad(options){
		},
		methods:{
			inputAction(e,name){
				this[name] = e.detail.value;
			},
			submit(){
				if(this.isnew == this.renew){
					this.showTips = false;
					let option = {
						old_pwd:this.old,
						new_pwd:this.isnew,
					}
					$https('POST','changePassword',option,res=>{
						if(res.data.errcode==0){
							uni.showToast({
								title: '修改成功!请重新登录',
								icon:'none',
								success(){
									uni.removeStorageSync('copartner_token');
									setTimeout(function(){
										uni.navigateTo({
											 url: '/subpack/account/login'
										});
									},2000)
								}
							});
						}else{
							uni.showToast({
								title:res.data.errmsg,
								icon:'none'
							})
						}
					})
				}else{
					//两次密码不一致
					this.showTips = true;

				}
			},
			back(){
				// #ifdef H5
					window.history.back(-1);
				// #endif 
				// #ifndef H5
				uni.navigateBack();
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		.edit{
			padding:20rpx 40rpx;
			color:#191919;
			.row{
				padding:22rpx 0 0;
				border-bottom:2px solid #ECECEC;
				.prop{
					font-size: 26rpx;
					font-weight: 600;
				}
				input{
					font-size: 24rpx;
					margin-top:24rpx;
					padding-left:8rpx;
				}
			}
		}
		.submit{
			width: 566rpx;
			height: 88rpx;
			color:#fff;
			background: $dgreen;
			box-shadow: 0px 2rpx 14rpx 2rpx rgba(0,0,0,0.2);
			border-radius: 48rpx;
			margin:60rpx auto;
		}
		.tips{
			color:#E84B4B;
		}
	}
</style>
